#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, a[1220010];
int z;
int find(int x)
{
	if(a[x] == x)
		return x;
	else
		return a[x] = find(a[x]);
}
void un_set(int x, int y)
{
	a[find(x)] = find(y);
}
int main()
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		a[i] = i;
	for(int i = 1; i <= m; i++) 
	{
		cin >> z >> x >> y;
		if(z == 1)
			un_set(x, y);
		if(z == 2)
		{
			int w = find(x), e = find(y);
			if(w == e)
				puts("Y");
			else
				puts("N");
		}
	}
	return 0;
}